<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/5/9
  Time: 16:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <title>Title</title>
    <script src="<%=basePath%>/js/jquery-2.1.0.js"></script>
    <script src="<%=basePath%>/js/jquery.form.js"></script>
    <script>
        function doUpload() {
            var formData = new FormData($( "#uploadForm" )[0]);
            $.ajax({
                url: '<%=basePath%>upload/toUpload2.do' ,
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (returndata) {
                    alert(returndata);
                },
                error: function (returndata) {
                    alert(returndata);
                }
            });
        }
    </script>
</head>
<body>
<h1>使用spring mvc提供的类的方法上传文件</h1>
<
<form name="Form1" action="<%=basePath%>upload/toUpload.do" method="post"  enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="upload"/>
</form>


<h1>使用ajax spring mvc提供的类的方法上传文件</h1>

<form id= "uploadForm">
    <p >上传文件： <input type="file" name="file"/></p>
    <input type="button" value="上传" onclick="doUpload()" />
</form>
</body>
</html>
